package me.cxlr.shaopinghelper.widget;

import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.SeekBar;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.AppCompatSeekBar;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.appcompat.widget.LinearLayoutCompat;
import androidx.cardview.widget.CardView;

import me.cxlr.shaopinghelper.R;

/**
 * 控件--卡片式Seekbar
 *
 * @author ShanLunZhi
 */
public class CardViewSeekBarWidget extends LinearLayoutCompat {
    private Context context;
    private View view;
    private CardView cardView;
    private LinearLayoutCompat llcRoot;
    private AppCompatTextView textViewTitle;
    private AppCompatTextView textViewMessage;
    private AppCompatSeekBar seekBar;

    public CardViewSeekBarWidget(@NonNull Context context) {
        super(context);
        this.context = context;
        initWidget();
    }

    public CardViewSeekBarWidget(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        initWidget();
    }

    private void initWidget() {
        view = LayoutInflater.from(context).inflate(R.layout.widget_cardview_seekbar, this);
        cardView = view.findViewById(R.id.wcs_cv);
        llcRoot = view.findViewById(R.id.wcs_ll_root);
        textViewTitle = view.findViewById(R.id.wcs_tv_title);
        textViewMessage = view.findViewById(R.id.wcs_tv_message);
        seekBar = view.findViewById(R.id.wcs_sb);

        cardView.setRadius(35F);
    }

    public void setTitle(int resourceId) {
        textViewTitle.setText(resourceId);
    }

    public void setTitle(CharSequence title) {
        textViewTitle.setText(title);
    }

    public void setMessage(int resourceId) {
        textViewMessage.setText(resourceId);
    }

    public void setMessage(CharSequence title) {
        textViewMessage.setText(title);
    }

    /**
     * 设置SeekBar最小值和最大值
     *
     * @param min 最小值
     * @param max 最大值
     */
    public void setSeekBarMinAndMax(int min, int max) {
        setSeekBarMin(min);
        setSeekBarMax(max);
    }

    /**
     * 设置SeekBar最小值
     *
     * @param min 最小值
     */
    public void setSeekBarMin(int min) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            seekBar.setMin(min);
        }
    }

    /**
     * 设置SeekBar最大值
     *
     * @param max 最大值
     */
    public void setSeekBarMax(int max) {
        seekBar.setMax(max);
    }

    public void setProgress(int progress) {
        seekBar.setProgress(progress);
    }

    public void setOnSeekBarChangeListener(SeekBar.OnSeekBarChangeListener onSeekBarChangeListener) {
        seekBar.setOnSeekBarChangeListener(onSeekBarChangeListener);
    }
}
